---
id: indexing
title: Indexing functions
sidebar_label: Indexing
slug: /api/indexing
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

These functions are used for finding the H3 cell index containing coordinates, and for finding the center and boundary of H3 indexes.

## latLngToCell

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Python', value: 'python'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
  ]
}>
<TabItem value="c">

```c
H3Error latLngToCell(const LatLng *g, int res, H3Index *out);
```

</TabItem>
<TabItem value="python">

```py
h3.latlng_to_cell(lat, lng, resolution)
```

</TabItem>
<TabItem value="java">

```java
long latLngToCell(double lat, double lng, int res);
String latLngToCellAddress(double lat, double lng, int res);
```

</TabItem>
<TabItem value="javascript">

```js
h3.latLngToCell(lat, lng, res)
```

```js live
function example() {
  const lat = 45;
  const lng = 40;
  const res = 2;
  return h3.latLngToCell(lat, lng, res);
}
```

</TabItem>
</Tabs>

Indexes the location at the specified resolution, returning the index of the cell containing the location. This buckets
the geographic point into the H3 grid. See the [algorithm description](../core-library/latLngToCellDesc) for more information.

Returns 0 (`E_SUCCESS`) on success.

## cellToLatLng

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Python', value: 'python'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
  ]
}>
<TabItem value="c">

```c
H3Error cellToLatLng(H3Index cell, LatLng *g);
```

</TabItem>
<TabItem value="python">

```py
h3.cell_to_latlng(cell)
```

</TabItem>
<TabItem value="java">

```java
LatLng cellToLatLng(long cell);
LatLng cellToLatLng(String cellAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.cellToLatLng(cell)
```

```js live
function example() {
  const cell = '85283473fffffff';
  return h3.cellToLatLng(cell);
}
```

</TabItem>
</Tabs>

Finds the center of the cell in grid space. See the
[algorithm description](../core-library/cellToLatLngDesc) for
more information.

The center will drift versus the centroid
of the cell on Earth due to distortion from the gnomonic
projection within the icosahedron face it resides on and its
distance from the center of the icosahedron face.

Returns 0 (`E_SUCCESS`) on success.

## cellToBoundary

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Python', value: 'python'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
  ]
}>
<TabItem value="c">

```c
H3Error cellToBoundary(H3Index cell, CellBoundary *bndry);
```

</TabItem>
<TabItem value="python">

```py
h3.cell_to_boundary(cell, geo_json=False)
```

</TabItem>
<TabItem value="java">

```java
List<LatLng> cellToBoundary(long cell);
List<LatLng> cellToBoundary(String cellAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.cellToBoundary(cell, [formatAsGeoJson])
```

```js live
function example() {
  const cell = '85283473fffffff';
  return h3.cellToBoundary(cell);
}
```

</TabItem>
</Tabs>

Finds the boundary of the cell. See the
[algorithm description](../core-library/cellToBoundaryDesc)
for more information.


Returns 0 (`E_SUCCESS`) on success.
